using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.Text.Style;
using Android.Text;
using Android.Graphics;

namespace CPXamarin
{
    public class AlphaForegroundColorSpan : ForegroundColorSpan 
    {
        private float mAlpha;

        public AlphaForegroundColorSpan(Color color):base(color)
        {
            
        }

        public AlphaForegroundColorSpan(Parcel src):base(src)
        {
           
            mAlpha = src.ReadFloat();
        }
        public void writeToParcel(Parcel dest, ParcelableWriteFlags flags) 
        {
            base.WriteToParcel(dest, flags);
            dest.WriteFloat(mAlpha);
        }

        public override void UpdateDrawState(TextPaint ds)
        {

            ds.Color = GetAlphaColor();
        }

        public void setAlpha(float alpha) 
        {
           mAlpha = alpha;
        }
        public float getAlpha() 
        {
        return mAlpha;
        }

        private Color GetAlphaColor() 
        {
        int foregroundColor = ForegroundColor;
        return Color.Argb((int) (mAlpha * 255), Color.Red, Color.Green, Color.Blue);
        }

    }
}